﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Presenter.Users;

namespace SocialNetworkClient.Pages.User
{
    public partial class All : System.Web.UI.Page, IUserAllView
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserAllPresenter"] != null)
            {
                var presenter = Session["UserAllPresenter"] as UserAllPresenter;
                if (presenter != null)
                    presenter.Reload(this);
            }
            else
            {
                Session["UserAllPresenter"] = new UserAllPresenter(this);
            }
        }

        #region Implementation of ISignUpView

        public void GetAll(List<List<string>> collection)
        {
            UserTable.Rows.Clear();

            var headerRow = new TableRow();
            headerRow.Cells.Add(new TableCell { Text = "<b>Id</b>" });
            headerRow.Cells.Add(new TableCell { Text = "<b>Email</b>" });
            headerRow.Cells.Add(new TableCell { Text = "<b>Nickname</b>" });
            headerRow.Cells.Add(new TableCell { Text = "<b>Fullname</b>" });
            headerRow.Cells.Add(new TableCell { Text = "<b>Job</b>" });
            headerRow.Cells.Add(new TableCell { Text = "<b>Birthday</b>" });
            headerRow.Cells.Add(new TableCell { Text = "<b>Interests</b>" });
            headerRow.Cells.Add(new TableCell { Text = "<b>Groups</b>" });
            headerRow.Cells.Add(new TableCell { Text = "<b>Diary</b>" });
            UserTable.Rows.Add(headerRow);


            foreach (var item in collection)
            {
                var row = new TableRow();

                foreach (var cellStr in item)
                {
                    var cell = new TableCell {Text = cellStr};
                    row.Cells.Add(cell);
                }

                var interestCell = new TableCell { Text = "<a href='" + Page.ResolveClientUrl("~/Pages/User/Interests.aspx") + "?id=" + item[0] + "'>Interests</a>" };
                var groupCell    = new TableCell { Text = "<a href='" + Page.ResolveClientUrl("~/Pages/User/Groups.aspx")    + "?id=" + item[0] + "'>Groups</a>" };
                var diaryCell    = new TableCell { Text = "<a href='" + Page.ResolveClientUrl("~/Pages/User/DiaryMessages.aspx") + "?id=" + item[0] + "'>Diary</a>" };

                row.Cells.Add(interestCell);
                row.Cells.Add(groupCell);
                row.Cells.Add(diaryCell);

                UserTable.Rows.Add(row);
            }
        }

        #endregion
    }
}